<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="6" :sm="24">
            <a-form-item label="项目名称" >
              <a-input placeholder="请输入项目名称" v-model="queryParam.projectName"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="6" :sm="24">
            <a-form-item label="项目类型">
              <a-input placeholder="请输入项目类型" v-model="queryParam.projectType"></a-input>
            </a-form-item>
          </a-col>
          <!--日期选择-->
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="6" :sm="24">
              <a-form-item label="时间区间">
                <a-range-picker @change="onChange"/>
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'"/>
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->
    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>

      <a-button @click="select" type="primary" value="" >全部</a-button>
      <a-button @click="select" type="primary" value="BEGIN" >未抽取</a-button>
      <a-button @click="select" type="primary" value="WAIT" >待确认</a-button>
      <a-button @click="select" type="primary" value="RUNNING" >抽取中</a-button>
      <a-button @click="select" type="primary" value="FINISH" >已完成</a-button>
      <a-button @click="select" type="primary" value="OVER" >已结束</a-button>
      <a-button @click="select" type="primary" value="WARN" >抽取失败</a-button>

      <a-dropdown v-if="selectedRowKeys.length > 0">
        <a-menu slot="overlay">
          <a-menu-item key="1" @click="batchDel">
            <a-icon type="delete"/>
            删除
          </a-menu-item>
          <!--<a-menu-item key="2" @click="professorRandomChoose"><a-icon type="user-add" />专家抽取</a-menu-item>-->
        </a-menu>
        <a-button style="margin-left: 8px"> 批量操作
          <a-icon type="down"/>
        </a-button>
      </a-dropdown>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{
          selectedRowKeys.length
        }}</a>项
        <a v-if="selectedRowKeys.length!=0" style="margin-left: 24px" @click="onClearSelected">清空选择</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
        class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="25px" alt=""
               style="max-width:80px;font-size: 12px;font-style: italic;"/>
        </template>

        <!--项目状态-->
        <span slot="projectStatus" slot-scope="text,record">
          <a
            :class="record.projectStatus==='FINISH' ? 'fontgreen' :(record.projectStatus==='RUNNING' ? 'fontyellow' : 'fontred')">{{ initStatus(record.projectStatus) }}</a>
        </span>

        <span slot="action" slot-scope="text, record">
           <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
           </a-popconfirm>
          <a-divider type="vertical"/>
          <a-popconfirm title="确定要修改项目信息吗?" @confirm="() => handleEdit(record)">
               <a :disabled="!((record.projectStatus=='BEGIN') || (record.projectStatus=='WARN'))">编辑</a>
          </a-popconfirm>
        </span>
        <span slot="actionnew" slot-scope="text, record">
            <!--评价组件 :project="record" -->
          <ProjectProfessorComments :project="record" />
          <a-divider type="vertical"/>
          <a v-if='record.projectStatus=="BEGIN"' @click="professorRandomChoose2(record)">权重抽取</a>
          <a-divider type="vertical"/>
          <a v-if='record.projectStatus=="BEGIN"' @click="professorRandomChoose1(record)">随机抽取</a>
          <a v-else @click="handleAdd1(record)">抽取状态</a>
        </span>
      </a-table>
    </div>
    <projectProfessorInfo-modal ref="modalForm" @ok="modalFormOk" ></projectProfessorInfo-modal>
   <ProjectOwnProfessor-list ref="OwnForm" @ok="modalFormOk"></ProjectOwnProfessor-list>
  </a-card>
</template>
<style>
.choose {

  color: #ee9900;
}

.notChoose {

  color: #e8e8e8;
}

.fontgreen {
  color: green;
}

.fontyellow {
  color: gold;
}

.fontred {
  color: red;
}

.fontdelete {
  color: #aaa0a0;
}
</style>
<script>

import {deleteAction, getAction, downFile, getFileAccessHttpUrl} from '@/api/manage'
import '@/assets/less/TableExpand.less'
import {loadCategoryData} from '@/api/api'
import {mixinDevice} from '@/utils/mixin'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import ProjectProfessorInfoModal from './modules/ProjectProfessorInfoModal'
import ProjectOwnProfessorList from './modules/ProjectOwnProfessorList'
import {filterMultiDictText} from '@/components/dict/JDictSelectUtil'
import ProjectProfessorComments from "./modules/ProjectProfessorComments";

export default {
  name: "ProjectProfessorInfoList",
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    ProjectOwnProfessorList,
    ProjectProfessorInfoModal,
    ProjectProfessorComments
  },
  data() {
    return {
      queryParam: {},
      description: '项目所需专家抽取状态管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '项目名称',
          align: "center",
          width: 250,
          dataIndex: 'projectName'
        },
        {
          title: '评标时间',
          align: "center",
          width: 250,
          dataIndex: 'professorWorkBeginTime'
        },
        {
          title: '评标地点',
          align: "center",
          width: 250,
          dataIndex: 'professorWorkAddress'
        },
        {
          title: '项目状态',
          align: "center",
          width: 250,
          scopedSlots: {customRender: 'projectStatus'},
        },
        {
          title: '操作',
          align: "center",
          width: 150,
          scopedSlots: {customRender: 'actionnew'},
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          // fixed:"right",
          width: 130,
          scopedSlots: {customRender: 'action'}
        }
      ],
      url: {
        list:"/projectProfessorInfo/list",
        delete: "/projectProfessorInfo/delete",
        deleteBatch: "/projectProfessorInfo/deleteBatch",
        exportXlsUrl: "/projectProfessorInfo/exportXls",
        importExcelUrl: "/projectProfessorInfo/importExcel",
        randomChoose: "/projectProfessorInfo/randomChoose",
        queryProfessorNumber: "/projectProfessorInfo/queryProfessorNumber"
      },
      dictOptions: {},
      bpmStatusDictOptions: [],
    }
  },

  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`;
    },
  },
  methods: {
    select(event){
      var str=event.target.value;
      this.queryParam.projectStatus=str;
      var params = this.getQueryParams();//查询条件

      console.log("params"+JSON.stringify(params));
      console.log("这是select方法");
      this.searchQuery();
      // getAction(this.url.list, params).then((res) => {
      //   if (res.success) {
      //     this.dataSource = res.result.records;
      //     this.ipagination.total = res.result.total;
      //   }
      //   if(res.code===510){
      //     this.$message.warning(res.message)
      //   }
      //   this.loading = false;
      // })
    },
    initStatus(projectStatus) {
      let statusArr = ['BEGIN', 'RUNNING', 'FINISH', 'WARN', 'WAIT', 'OVER']
      let codeArr = ['未抽取', '抽取中', '已完成', '专家库人数不足', '待确认', '已结束']
      for (let i = 0; i < statusArr.length; i++) {
        if (projectStatus === statusArr[i]) {
          return codeArr[i]
        }
      }
    },
    onChange(date, dateString) {
      // 把值分别存储
      let beginDate = dateString[0]
      let overDate = dateString[1]
      // 把值放入queryParam中
      this.queryParam.beginDate = beginDate
      this.queryParam.overDate = overDate

    },
    // Sampling(formData){
    //   this.professorRandomChoose2(formData);
    // },
    show(record) {
      console.log(record)
    },
    initDictConfig() {
      loadCategoryData({code: 'B03'}).then((res) => {
        if (res.success) {
          this.$set(this.dictOptions, 'professorType', res.result)
        }
      })
    },
    professorRandomChoose2:function(record){
      var id = record.id;
      if (record.projectStatus == "FINISH" || record.projectStatus == "RUNNING" || record.projectStatus == "OVER") {
        this.$message.warn("该项目已经抽取过专家");
      } else if (record.projectStatus == "WAIT") {
        this.$router.push({
          name: 'diy-ProjectOwnProfessorList',
          query: {
            projectId: record.id
          }
        })
      } else {
        if (!this.url.queryProfessorNumber) {
          this.$message.error("请设置url.queryProfessorNumber属性!")
          return
        }
        if (!this.url.randomChoose) {
          this.$message.error("请设置url.randomChoose属性!")
          return
        }
        var ids = "";
        ids = id;
        let ids2 ='权重'
        var that = this;
        this.$confirm({
          title: "抽取专家",
          content: "是否权重抽取?",
          onOk: function () {
            that.loading = true;
            getAction(that.url.queryProfessorNumber + "/" + id).then((res) => {
              if (res.success) {
                deleteAction(that.url.randomChoose, {ids: ids ,ids2:ids2}).then((res) => {
                  if (res.success) {
                    that.$message.success(res.message);
                    that.loadData();
                    that.onClearSelected();
                    that.handleAdd1(record);
                  } else {
                    that.$message.warning(res.message);
                  }
                }).finally(() => {
                  that.loading = false;
                });
              } else {
                that.$message.warning(res.message);
              }

            }).finally(() => {that.loading = false;})

          },
        });
      }
    },
    professorRandomChoose1:function(record){
      var id = record.id;
      if (record.projectStatus == "FINISH" || record.projectStatus == "RUNNING" || record.projectStatus == "OVER") {
        this.$message.warn("该项目已经抽取过专家");
      } else if (record.projectStatus == "WAIT") {
        this.$router.push({
          name: 'diy-ProjectOwnProfessorList',
          query: {
            projectId: record.id
          }
        })
      } else {
        if (!this.url.queryProfessorNumber) {
          this.$message.error("请设置url.queryProfessorNumber属性!")
          return
        }
        if (!this.url.randomChoose) {
          this.$message.error("请设置url.randomChoose属性!")
          return
        }
        var ids = "";
        ids = id;
        let ids2 ='随机'
        var that = this;
        this.$confirm({
          title: "抽取专家",
          content: "是否随机抽取?",
          onOk: function () {
            that.loading = true;
            getAction(that.url.queryProfessorNumber + "/" + id).then((res) => {
              if (res.success) {
                deleteAction(that.url.randomChoose, {ids: ids,ids2:ids2}).then((res) => {
                  if (res.success) {
                    that.$message.success(res.message);
                    that.loadData();
                    that.onClearSelected();
                    that.handleAdd1(record);
                  } else {
                    that.$message.warning(res.message);
                  }
                }).finally(() => {
                  that.loading = false;
                });
              } else {
                that.$message.warning(res.message);
              }

            }).finally(() => {that.loading = false;})

          },
        });
      }
    }
  }
}
</script>
<style scoped>
/*@import '~@assets/less/common.less';*/

</style>